<?php

namespace App\Services;

use App\Http\Resources\Home\StoreResource\StoreCollection;
use App\Http\Resources\Home\StoreResource\StoreJoin;
use App\Models\HouseInfo;
use App\Models\RecoveryInfo;
use App\Models\RemoverInfo;
use App\Models\TutorInfo;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class HouseCateService extends BaseService
{
    public $cateType = [1,2,3,4];

    /**
     * 根据type获取列表数据【家政，家教，搬家公司，回收站】
     * @return array
     * @author ypp
     * @date 2021/03/04
     */
    public function getInfoListByType()
    {
        $type = request()->type;
        $cateId = request()->cate_id;
        //获取认证用户信息
        $user_info = auth('user')->user();
        $where['estate_id'] = $user_info['property_id'];
        if(!in_array($type,$this->cateType)){
            return $this->format_error('参数错误');
        }
        $where['status'] = 1;
        $where['is_show'] = 1;
        if($cateId){
            $where['cate_id'] = $cateId;
        }
        switch ($type){
            case 1:
                $model = new HouseInfo(); //家政
                break;
            case 2:
                $model = new RemoverInfo(); //搬家公司
                break;
            case 3:
                $model = new TutorInfo(); //家教
                break;
            case 4:
                $model = new RecoveryInfo();
                break;

        }
        $list = $model
            ->where($where)
            -> orderBy('id')
            ->select()
            -> paginate(request()->per_page ?? 10)
            -> toArray();
        return $this->format($list);
    }

    /**
     * 根据type和id获取详情【家政，家教，搬家公司，回收站】
     * @return array
     * @author ypp
     * @date 2021/03/04
     */
    public function getInfoDetailByType($type,$id)
    {
        if(!in_array($type,$this->cateType)){
            return $this->format_error('参数错误');
        }
        switch ($type){
            case 1:
                $model = new HouseInfo(); //家政
                break;
            case 2:
                $model = new RemoverInfo(); //搬家公司
                break;
            case 3:
                $model = new TutorInfo(); //家教
                break;
            case 4:
                $model = new RecoveryInfo();
                break;
        }
        $detail = $model->find($id);
        if($detail){
            return $this->format($detail);
        }else{
            return $this->format_error('数据不存在');
        }

    }

}
